1461E - Water Level - CodeForces Solution


brute force graphs greedy implementation math *2200

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PII pair<ll,ll>
#define inf 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof a)
#define endl '\n'
const ll N=1e6+5;
const ll eps=1e-8;
const ll mod=998244353;
bool cmp(ll a,ll b){return a>b;}
ll lowbit(ll x){return x&-x;}
ll Abs(ll x){return x>0?x:-x;}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1,y=0;return a;}ll d=exgcd(b,a%b,y,x);y-=a/b*x;return d;}
ll ksm(ll a,ll b,ll c){ll sum=1;while(b){if(b&1)sum=sum*a%c;a=a*a%c;b>>=1;}return sum;}
//ll h[N],e[N*2],ne[N*2],w[N*2],idx;void add(ll a,ll b,ll c){e[idx]=b,ne[idx]=h[a],h[a]=idx,w[idx++]=c;}
//ll fa[N],siz[N];ll ifind(ll x){return x==fa[x]?x:fa[x]=ifind(fa[x]);}
ll n,m;
void solve()///x==y就判断上下界出不出界
///x>y-->第一天能加就加,有可能加不上,然后喝一个x,之后就计算能撑几天
///x<y-->第一天能加就加,有可能加不上,有可能喝一口就没了,之后就是喝几天加一天,判断循环
{
    map<ll,ll> dl;
    ll k,l,r,t,x,y;
    cin>>k>>l>>r>>t>>x>>y;///用x加y
    if(x==y)///三种情况讨论
    {
        if(k-x>=l || k+y<=r) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    else if(x>y)
    {
        ll down=(x-y);
        ll now=0;
        if(k+y<=r) k+=y;///第一天特判
        if(k-x>=l)
        {
            k-=x;///第一天喝水
            now++;
            now+=(k-l)/down;///之后按照这个操作能坚持几天
        }
        if(now>=t) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    else if(x<y)
    {
        ll now=0;
        while(now<t)
        {
            if(k+y<=r) k+=y;
            ll pp=(k-l)/x;
            if(dl[k]==1)
            {
                cout<<"Yes"<<endl;
                return ;
            }
            if(pp==0)
            {
                cout<<"No"<<endl;return ;
            }
            now+=pp;
            dl[k]=1;
            k-=pp*x;
        }
        cout<<"Yes"<<endl;
    }
}
int main(){
    ios::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
    ll tt = 1 ;
    //cin>>tt;
    while(tt--) solve();
}

    			 	 	  				   						   		


Comments

Submit
0 Comments
More Questions

1665D - GCD Guess
29A - Spit Problem
1097B - Petr and a Combination Lock
92A - Chips
1665B - Array Cloning Technique
1665A - GCD vs LCM
118D - Caesar's Legions
1598A - Computer Game
1605A - AM Deviation
1461A - String Generation
1585B - Array Eversion
1661C - Water the Trees
1459A - Red-Blue Shuffle
1661B - Getting Zero
1661A - Array Balancing
1649B - Game of Ball Passing
572A - Arrays
1455A - Strange Functions
1566B - MIN-MEX Cut
678C - Joty and Chocolate
1352E - Special Elements
1520E - Arranging The Sheep
1157E - Minimum Array
1661D - Progressions Covering
262A - Roma and Lucky Numbers
1634B - Fortune Telling
1358A - Park Lighting
253C - Text Editor
365B - The Fibonacci Segment
75A - Life Without Zeros